/**
 * Class: OpenLayers.Control.ArcRestPolygonQuery
 * 
 * 框选控件，实现拉框查询
 * 
 * 继承自:
 *  - <OpenLayers.Control.ArcRestPointQuery>
 * @requires extend/Control/ArcRestPointQuery.js
 */
OpenLayers.Control.ArcRestPolygonQuery = OpenLayers.Class(OpenLayers.Control.ArcRestPointQuery, {
    
    /**
	   * Property: title
	   * {String} 工具按钮提示文字
	   */
    title: "多边形选择",
        
	/**
	 * Method: initialize
	 * 初始化
	 */
    initialize: function (options) {
		   OpenLayers.Control.ArcRestPointQuery.prototype.initialize.apply(this, arguments);
  	},
    
	/**
	 * Method: activate
	 * 控件被触发时设置鼠标手势
	 */
	activate: function(){
		OpenLayers.Control.prototype.activate.apply(this, arguments);
	},

    /**
     * Method: draw
     */    
    draw: function() {
	    this.handler = new OpenLayers.Handler.Polygon( this,
	                        {done: this.executeQuery}, {keyMask: this.keyMask,layerOptions: {styleMap: this.styleMap}});	  
    },
    
    //待开发
    evtToCoord:function(evt){
        if (evt instanceof OpenLayers.Geometry.Polygon) {
	    	var polygon = evt+"";
	    	polygon = polygon.substring(9,polygon.length-2);
	    	polygon = polygon.replace(/ /g,",");
	    	return polygon;
    	} else { // it's a pixel
            alert("请做多边形查询！");
            return null;
        }
    },
    
    /**
    * Method: destroy
    * The destroy method is used to perform any clean up before the control
    * is dereferenced.  Typically this is where event listeners are removed
    * to prevent memory leaks.
    */
   destroy: function () {
       if(this.events) {
           if(this.eventListeners) {
               this.events.un(this.eventListeners);
           }
           this.events.destroy();
           this.events = null;
       }
       this.eventListeners = null;

       // eliminate circular references
       if (this.handler) {
    	   this.handler.deactivate();
           this.handler.destroy();
           this.handler = null;
       }
       if(this.handlers) {
           for(var key in this.handlers) {
               if(this.handlers.hasOwnProperty(key) &&
                  typeof this.handlers[key].destroy == "function") {
                   this.handlers[key].destroy();
               }
           }
           this.handlers = null;
       }
       if (this.map) {
           this.map.removeControl(this);
           this.map = null;
       }
   },
    
    CLASS_NAME: "OpenLayers.Control.ArcRestPolygonQuery"
});

